import { defineStore } from "pinia";
import { AuthState } from "@/stores/interface";
import { getFlatMenuList, getShowMenuList, getAllBreadcrumbList } from "@/utils";

export const useAuthStore = defineStore({
  id: "friends-auth",
  state: (): AuthState => ({
    // 按钮权限列表
    authButtonList: {},
    // 菜单权限列表
    authMenuList: [],
    // 当前页面的 router name，用来做按钮权限筛选
    routeName: ""
  }),
  getters: {
    // 按钮权限列表
    authButtonListGet: state => state.authButtonList,
    // 菜单权限列表 ==> 这里的菜单没有经过任何处理
    authMenuListGet: state => state.authMenuList,
    // 菜单权限列表 ==> 左侧菜单栏渲染，需要剔除 isHide == true
    showMenuListGet: state => getShowMenuList(state.authMenuList),
    // 菜单权限列表 ==> 扁平化之后的一维数组菜单，主要用来添加动态路由
    flatMenuListGet: state => getFlatMenuList(state.authMenuList),
    // 递归处理后的所有面包屑导航列表
    breadcrumbListGet: state => getAllBreadcrumbList(state.authMenuList)
  },
  actions: {
    // Get AuthMenuList
    async getAuthMenuList() {
      // const { data } = await getAuthMenuListApi();
      // console.log("555", data);
      const arr = [
        {
          path: "/home/index",
          name: "home",
          component: "/home/index",
          meta: {
            icon: "HomeFilled",
            title: "首页",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/person/index",
          name: "person",
          component: "/person/index",
          meta: {
            icon: "User",
            title: "个微加好友",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/enterprise/index",
          name: "enterprise",
          component: "/enterprise/index",
          meta: {
            icon: "FolderAdd",
            title: "企微加好友",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/messageWarn/index",
          name: "messageWarn",
          component: "/messageWarn/index",
          meta: {
            icon: "Message",
            title: "消息提醒",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/accountManagement/index",
          name: "accountManagement",
          component: "/accountManagement/index",
          meta: {
            icon: "UserFilled",
            title: "账号管理",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/selectAccount/index",
          name: "selectAccount",
          component: "/selectAccount/index",
          meta: {
            icon: "SemiSelect",
            title: "选择账号",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/addRecord/index",
          name: "addRecord",
          component: "/addRecord/index",
          meta: {
            icon: "Tickets",
            title: "加好友记录",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/browseChannels/index",
          name: "browseChannels",
          component: "/browseChannels/index",
          meta: {
            icon: "Film",
            title: "浏览视频号",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/browseGlance/index",
          name: "browseGlance",
          component: "/browseGlance/index",
          meta: {
            icon: "Monitor",
            title: "浏览看一看",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/browseStatistics/index",
          name: "browseStatistics",
          component: "/browseStatistics/index",
          meta: {
            icon: "DataLine",
            title: "浏览统计",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/browseLog/index",
          name: "browseLog",
          component: "/browseLog/index",
          meta: {
            icon: "Memo",
            title: "浏览日志",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/userManagement/index",
          name: "userManagement",
          component: "/userManagement/index",
          meta: {
            icon: "UserFilled",
            title: "用户管理",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        },
        {
          path: "/permissionsManagement/index",
          name: "permissionsManagement",
          component: "/permissionsManagement/index",
          meta: {
            icon: "Grid",
            title: "权限管理",
            isLink: "",
            isHide: false,
            isFull: false,
            isAffix: true,
            isKeepAlive: false
          }
        }
      ];
      this.authMenuList = arr;
    },
    // Set RouteName
    async setRouteName(name: string) {
      this.routeName = name;
    }
  }
});
